package org.endy.leisure.diaTracker.service

import org.endy.leisure.diaTracker.entity.User
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class UserServiceTest {

    @Autowired
    private lateinit var userService: UserService

    private val openId = "1234554321"

    @Test
    fun login() {
        val user = userService.login(openId)
        assertEquals(openId, user?.id)
    }

    @Test
    fun createUser() {
        val user = User(
            id = openId
        )

        userService.createUser(user)
    }

    @Test
    fun updateUser() {
        val user = User(
            id = openId,
            nickname = "endy0114",
            avatar = "@ty"
        )
        userService.updateUser(user)

        val newUser = userService.login(openId)
        assertEquals("endy0114", newUser?.nickname)
    }

}